package com.wrial.utils;
/*
 * @Author  Wrial
 * @Date Created in 17:01 2020/8/15
 * @Description
 */

import java.util.*;

public class Main4 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        List<Road> roads = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            roads.add(new Road(scanner.next(), scanner.next()));
        }
        System.out.println(match(roads));
    }

    public static class Road {
        String s, e;

        Road(String s, String e) {
            this.s = s;
            this.e = e;
        }
    }

    public static int match(List<Road> nodes) {
        Stack<Road> stack = new Stack<>();
        int count = 0;
        for (int i = 0; i < nodes.size(); i++) {
            Road road = nodes.get(i);
            if (stack.isEmpty()) {
                stack.push(road);
            } else {
                Road pre = stack.peek();
                if (pre.e.equals(road.s)) {
                    road.s = pre.s;
                    stack.pop();
                }
                if (road.s.equals(road.e)) {
                    count += 1;
                }
                stack.push(road);
            }
        }
        return count;
    }
}
